package day12;
import java.util.Scanner;

public class Ship {
    public static void main(String[] args) {
        Test test=new Test();
         try{
             test.OverWeight();
         } catch (OverWeightException e) {
             System.err.println(e.getMessage());
         }
    }
}

class Test{
    public void OverWeight() throws OverWeightException{
        Scanner sc=new Scanner(System.in);
        double max=1000;
        double all=0;
        while(all<max){
            System.out.print("请输入重量:");
            double heavy=sc.nextDouble();
            all+=heavy;
            if (all>max){
                throw new OverWeightException("货轮超重，无法再装载重量为"+heavy+
                        "的货物货船将正点启航");
            }
            System.out.println("目前装载了"+all+"吨货物");
        }
    }
}

class OverWeightException extends Exception{
    public OverWeightException(){

    }
    public OverWeightException(String msg){
        super(msg);
    }
}